package com.ningxia.water.mapper;

import com.ningxia.water.entity.TsMeter;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ningxia.water.vo.out.MeterInfoVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *
 * @author hz
 * @since 2021-03-15
 */
public interface TsMeterMapper extends BaseMapper<TsMeter> {

    /**
     * 通过机井Id查询详细设备信息
     * @param wellId
     * @return
     */
    @Select("SELECT\n" +
            "\twm.well_id,\n" +
            "\tm.meter_id,\n" +
            "\tm.meter_code,\n" +
            "\tm.meter_name,\n" +
            "\tm.create_time,\n" +
            "\tm.STATUS,\n" +
            "\tm.meter_no,\n" +
            "\tmt.meter_no_name,\n" +
            "\tmt.meter_type,\n" +
            "\tmt.meter_vc, \n" +
            "\tmt.meter_caliber\t" +
            "FROM\n" +
            "\tts_well_meter wm\n" +
            "\tLEFT JOIN ts_meter m ON m.meter_id = wm.meter_id\n" +
            "\tLEFT JOIN ts_meter_type mt ON mt.meter_no = m.meter_no \n" +
            "WHERE\n" +
            "\twm.well_id = #{wellId}")
    List<MeterInfoVo> findByWellId(Integer wellId);


    /**
     * 根据设备状态获取设备总数
     * @param status
     * @return
     */
    @Select("select count(1) from ts_meter where status = #{status}")
    Integer findByStatus(Integer status);


    /**
     * 根据设备meterCode（设备编号）查找meterId
     * @param meterCode
     * @return
     */
    @Select("select distinct meter_id from ts_meter where meter_code = #{meterCode}")
    Integer selectMeterIdByMeterCode(String meterCode);
}
